package cn.livingCloud.service.impl.operation;

import cn.livingCloud.context.BeanProvider;
import cn.livingCloud.dto.DeptFormDto;
import cn.livingCloud.entity.core.Dept;
import cn.livingCloud.repository.DeptMapper;
import com.alibaba.druid.util.StringUtils;

/**
 * Created by DingJie  on 2016/5/27.
 */
public class DeptFormDtoUpdater {
    protected transient DeptMapper mapper = BeanProvider.getBean(DeptMapper.class);
    private DeptFormDto formDto;

    public DeptFormDtoUpdater(DeptFormDto formDto) {
        this.formDto = formDto;
    }

    public String update() {
        String uuid = formDto.getUuid();
        if (StringUtils.isEmpty(uuid)) {
            Dept dept = new Dept();
            formDto.update(dept);
            mapper.insert(dept);
        } else {
            Dept dept = mapper.selectByPrimaryKey(uuid);
            formDto.update(dept);
            mapper.updateByPrimaryKey(dept);
        }
        return formDto.getParentUuid();
    }
}
